-------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Results\log\setup.log
  log type:  text
 opened on:   2 Oct 2023, 15:14:36

. 
. set type double, permanently 
(set type preference recorded)

. 
. 
. *** raw files used in analysis ****
. /*
> coordinates.dta             // geo coded variables of where all individuals live from Statistics Sweden
> valdistrikt_alla                // election districts from statistics Sweden, district level
> distrikt_0210.dta                       //election districts from Statistics Sweden, individual level  
> Birthyear_sex.dta                       // variables from statistics Sweden
> Birth_region.dta                        // variables from statistics Sweden
> Kommundata.dta                          // aggregated municipal level data from Statistics Sweden
> pol_id_complete                 // id-codes for everyone that has been a politician from Statistics Sweden
> nom_ko_X.dta                    // nominated politicians year X from Statistics Sweden
> valda_ko_X.dta                  // elected politicians year X from Statistics Sweden
> parl dist 2010.dta"  // election results from Valmyndigheten 2010
> mun dist 2010.dta    // election results from Valmyndigheten 2010
> roster parti distrikt alla val X.dta // election results from Valmyndigheten for year X
> all_price_transform.dta   // Housing prices from Mäklarstatistik
> tenure500_midpoint.dta   // Data on home ownership from GeoSweden
> mun competition.dta // Dataset from Folke, =., and Rickne, J. (2020) All the single ladies: Job promotions and the durability of ma
> rriage. Amerivan Economic Journal: Applied Economics, 12(1), 260-287
> 
> */
. 
. * Data from LISA registry is called directly via odbc load
. * Data from Fastighetsregistret (Building register) is called directly via odbc load
. * Data from Bygglovsregistret (Building permit register)  is called directly via odbc load
. 
. 
. *************************
. *****     LISA        ***
. *************************
. foreach year in 2002 2006 2010{
  2. if `year'==2002 odbc load, exec("select  Sun2000niva,inc=DispInk ,Barn7_10, Barn11_15, p_id=Person_LopNr from P0624_Lisa_2002") 
> dsn("P0624") clear
  3. else odbc load, exec("select  Sun2000niva, inc=DispInk04,Barn7_10, Barn11_15, p_id=Person_LopNr from P0624_Lisa_`year'") dsn("P0
> 624") clear     
  4. gen year =`year' 
  5. if `year'==2002 save "$dat\lisa_togeo", replace
  6. else append using "$dat\lisa_togeo"
  7. save "$dat\lisa_togeo", replace
  8. }
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\lisa_togeo.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\lisa_togeo.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\lisa_togeo.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\lisa_togeo.dta saved

. 
.         replace Sun2000niva="" if Sun2000niva=="*" | Sun2000niva=="-"
(0 real changes made)

.         destring Sun2000niva, replace force
Sun2000niva: all characters numeric; replaced as int

.         replace  Sun2000niva=. if Sun2000niva>=999
(589,798 real changes made, 589,798 to missing)

. 
. gen educ_year=.
(22,495,911 missing values generated)

. replace educ_year= 7.5 if Sun2000niva>=100 & Sun2000niva<200
(2,979,652 real changes made)

. replace educ_year= 9.4 if Sun2000niva>=200 & Sun2000niva<300
(3,100,088 real changes made)

. replace educ_year= 11.2 if Sun2000niva>=300 & Sun2000niva<330
(5,447,344 real changes made)

. replace educ_year= 12.4 if Sun2000niva>=330 & Sun2000niva<400
(4,138,173 real changes made)

. replace educ_year= 14.2 if Sun2000niva>=410& Sun2000niva<530
(2,709,512 real changes made)

. replace educ_year= 17 if Sun2000niva>=530 & Sun2000niva<600
(3,347,144 real changes made)

. replace educ_year= 20.4 if Sun2000niva>=600 & Sun2000niva<=1000
(184,200 real changes made)

. 
. gen child_7_15= Barn7_10+ Barn11_15

. 
. 
. joinby p_id using "$dat\Birthyear_sex.dta", unmatched(none)

. gen age=year-Fodelse

.         
. 
. joinby p_id using "$dat\Birth_region.dta", unmatched(master)

. drop _merge

. 
. g inv1g_ejsv=(FodelseVarldsdel!="Sverige") if !mi(FodelseVarldsdel)
(876 missing values generated)

. g inv1g_ejn=!inlist(FodelseVarldsdel, "Norden utom Sverige", "Sverige" )  if !mi(FodelseVarldsdel)
(876 missing values generated)

. g inv1g_eje=!inlist(FodelseVarldsdel, "Norden utom Sverige", "Sverige" , "Nordamerika", "EU28 utom Norden")  if !mi(FodelseVarldsde
> l)
(876 missing values generated)

. 
. 
. save "$dat\lisa_togeo", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\lisa_togeo.dta saved

. 
. 
. *************************
. *****  Politicians    ***
. *************************
. 
. * Grunddata för politikernas politiska information
. ****** vi gör en separat set up för det gamla datat då detta är annorlunda än det nya i strukture
.         
.         cd "\\micro.intra\Projekt\P0624$\P0624_Data"
\\micro.intra\Projekt\P0624$\P0624_Data

.         use "nom_ko_82.dta", clear

.         
.         append using "nom_ko_85.dta"

.         append using "nom_ko_88.dta"

.                 foreach var of varlist nrinom listnr ko_valkretskod llkk{
  2.         destring `var' , replace force
  3.         }
nrinom: contains nonnumeric characters; replaced as byte
(66 missing values generated)
listnr: all characters numeric; replaced as long
(638 missing values generated)
ko_valkretskod: all characters numeric; replaced as byte
(4 missing values generated)
llkk: all characters numeric; replaced as int
(2 missing values generated)

.         do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(559 real changes made)

. replace llkk = 1438 if llkk==1504
(430 real changes made)

. replace llkk = 1439 if llkk== 1507
(397 real changes made)

. replace llkk = 1440 if llkk==1521
(604 real changes made)

. replace llkk = 1441 if llkk== 1524
(638 real changes made)

. replace llkk = 1442 if llkk== 1527
(724 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(362 real changes made)

. replace llkk = 1445 if llkk==1603
(309 real changes made)

. replace llkk = 1446 if llkk== 1637
(240 real changes made)

. replace llkk = 1447 if llkk== 1643
(286 real changes made)

. replace llkk = 1452 if llkk== 1552
(416 real changes made)

. replace llkk = 1460 if llkk== 1560
(355 real changes made)

. replace llkk = 1461 if llkk== 1561
(455 real changes made)

. replace llkk = 1462 if llkk== 1562
(447 real changes made)

. replace llkk = 1463 if llkk== 1563
(1,456 real changes made)

. replace llkk = 1465 if llkk== 1565
(687 real changes made)

. replace llkk = 1466 if llkk== 1566
(455 real changes made)

. replace llkk = 1470 if llkk==1660
(501 real changes made)

. replace llkk = 1471 if llkk==1661
(352 real changes made)

. replace llkk = 1472 if llkk== 1662
(374 real changes made)

. replace llkk = 1473 if llkk== 1663
(379 real changes made)

. replace llkk = 1487 if llkk== 1580
(1,174 real changes made)

. replace llkk = 1488 if llkk== 1581
(1,140 real changes made)

. replace llkk = 1489 if llkk== 1582
(1,154 real changes made)

. replace llkk = 1490 if llkk== 1583
(5,955 real changes made)

. replace llkk = 1491 if llkk== 1584
(899 real changes made)

. replace llkk = 1492 if llkk== 1585
(475 real changes made)

. replace llkk = 1493 if llkk== 1680
(381 real changes made)

. replace llkk = 1494 if llkk== 1681
(856 real changes made)

. replace llkk = 1495 if llkk==1682
(322 real changes made)

. replace llkk = 1496 if llkk== 1683
(928 real changes made)

. replace llkk = 1497 if llkk== 1684
(332 real changes made)

. replace llkk = 1498 if llkk== 1685
(335 real changes made)

. replace llkk = 1499 if llkk== 1686
(975 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(242 real changes made)

. replace llkk = 643 if llkk==1623 
(254 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(622 real changes made)

. replace llkk =1257      if llkk==       1137
(765 real changes made)

. replace llkk =1270 if llkk==    1160    
(379 real changes made)

. replace llkk =1272      if llkk==       1162
(572 real changes made)

. replace llkk =1273      if llkk==       1163
(1,057 real changes made)

. replace llkk =1275 if llkk==    1165    
(356 real changes made)

. replace llkk =1276      if llkk==       1166
(497 real changes made)

. replace llkk =1277 if llkk==    1167    
(341 real changes made)

. replace llkk =1278 if llkk==    1168    
(380 real changes made)

. replace llkk =1290 if llkk==    1180    
(2,010 real changes made)

. replace llkk =1291      if llkk==       1181
(1,108 real changes made)

. replace llkk =1292      if llkk==       1182
(1,088 real changes made)

. replace llkk =1293      if llkk==       1183
(3,243 real changes made)

. 
end of do-file

.         
.         drop if llkk==.
(2 observations deleted)

.         
.         collapse (min) nrinom  , by(lopnr  partikod llkk  ar)

.         gen parti_initial = "M" if partikod=="0001"
(131,477 missing values generated)

.         replace parti_initial = "S" if partikod =="0002"
(46,817 real changes made)

.         replace parti_initial = "F" if partikod =="0003"
(20,908 real changes made)

.         replace parti_initial = "C" if partikod =="0004"
(33,755 real changes made)

.         replace parti_initial = "V" if partikod =="0005"
(10,216 real changes made)

.         replace parti_initial = "G" if partikod =="0055"
(4,995 real changes made)

.         replace parti_initial = "B" if partikod =="0110"
(0 real changes made)

.         replace parti_initial = "G" if partikod =="0055"
(0 real changes made)

.         replace parti_initial = "K" if partikod =="0068"
(9,884 real changes made)

.         
.         
.         replace parti_initial = "L" if  parti_initial=="" & partikod !=""
(4,902 real changes made)

.                 
.         save "$gdat\temp_rel_nom_old.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Data Extraction and Files\Data files\temp_rel_nom_old.dta saved

.         
.         use "valda_ko_82.dta", clear    

.         append using "valda_ko_85.dta"

.         append using "valda_ko_88.dta"

. 
.         destring llkk, replace force
llkk: all characters numeric; replaced as int

. 
. do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(82 real changes made)

. replace llkk = 1438 if llkk==1504
(82 real changes made)

. replace llkk = 1439 if llkk== 1507
(70 real changes made)

. replace llkk = 1440 if llkk==1521
(98 real changes made)

. replace llkk = 1441 if llkk== 1524
(80 real changes made)

. replace llkk = 1442 if llkk== 1527
(82 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(78 real changes made)

. replace llkk = 1445 if llkk==1603
(82 real changes made)

. replace llkk = 1446 if llkk== 1637
(70 real changes made)

. replace llkk = 1447 if llkk== 1643
(82 real changes made)

. replace llkk = 1452 if llkk== 1552
(89 real changes made)

. replace llkk = 1460 if llkk== 1560
(85 real changes made)

. replace llkk = 1461 if llkk== 1561
(82 real changes made)

. replace llkk = 1462 if llkk== 1562
(82 real changes made)

. replace llkk = 1463 if llkk== 1563
(102 real changes made)

. replace llkk = 1465 if llkk== 1565
(82 real changes made)

. replace llkk = 1466 if llkk== 1566
(82 real changes made)

. replace llkk = 1470 if llkk==1660
(49 real changes made)

. replace llkk = 1471 if llkk==1661
(82 real changes made)

. replace llkk = 1472 if llkk== 1662
(82 real changes made)

. replace llkk = 1473 if llkk== 1663
(41 real changes made)

. replace llkk = 1487 if llkk== 1580
(102 real changes made)

. replace llkk = 1488 if llkk== 1581
(120 real changes made)

. replace llkk = 1489 if llkk== 1582
(98 real changes made)

. replace llkk = 1490 if llkk== 1583
(157 real changes made)

. replace llkk = 1491 if llkk== 1584
(98 real changes made)

. replace llkk = 1492 if llkk== 1585
(81 real changes made)

. replace llkk = 1493 if llkk== 1680
(98 real changes made)

. replace llkk = 1494 if llkk== 1681
(102 real changes made)

. replace llkk = 1495 if llkk==1682
(97 real changes made)

. replace llkk = 1496 if llkk== 1683
(118 real changes made)

. replace llkk = 1497 if llkk== 1684
(66 real changes made)

. replace llkk = 1498 if llkk== 1685
(82 real changes made)

. replace llkk = 1499 if llkk== 1686
(102 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(70 real changes made)

. replace llkk = 643 if llkk==1623 
(70 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(82 real changes made)

. replace llkk =1257      if llkk==       1137
(90 real changes made)

. replace llkk =1270 if llkk==    1160    
(41 real changes made)

. replace llkk =1272      if llkk==       1162
(82 real changes made)

. replace llkk =1273      if llkk==       1163
(41 real changes made)

. replace llkk =1275 if llkk==    1165    
(70 real changes made)

. replace llkk =1276      if llkk==       1166
(93 real changes made)

. replace llkk =1277 if llkk==    1167    
(82 real changes made)

. replace llkk =1278 if llkk==    1168    
(98 real changes made)

. replace llkk =1290 if llkk==    1180    
(142 real changes made)

. replace llkk =1291      if llkk==       1181
(49 real changes made)

. replace llkk =1292      if llkk==       1182
(100 real changes made)

. replace llkk =1293      if llkk==       1183
(122 real changes made)

. 
end of do-file

.         gen llkk_2=llkk

.         
.                 gen parti_initial_v = "M" if partinamn=="MODERATA SAMLINGSPARTIET"
(32,648 missing values generated)

.         replace parti_initial_v = "S" if partinamn =="ARBETAREPARTIET SOCIALDEMOKRATERNA" |partinamn =="ARBETAREPARTIET-SOCIALDEMOK
> RATERNA"|partinamn =="ARBETAREPARTIET- SOCIALDEMOKRATERNA" 
(17,738 real changes made)

.         replace parti_initial_v = "F" if partinamn =="FOLKPARTIET"
(3,643 real changes made)

.         replace parti_initial_v = "C" if partinamn =="CENTERN" |partinamn =="CENTERPARTIET" 
(6,851 real changes made)

.         replace parti_initial_v = "V" if substr(partinamn, 3, 9) =="NSTERPART"
(1,786 real changes made)

.         replace parti_initial_v = "G" if substr(partinamn, 1, 4)=="MILJ"
(1,060 real changes made)

.         replace parti_initial_v = "K" if substr(partinamn, 1, 5)=="KRIST"
(941 real changes made)

.         replace parti_initial_v = "L" if  parti_initial_v=="" &  partinamn!=""
(629 real changes made)

.         
.         gen vald=1

. 
.         rename nrinom inval_ord

.         destring inval_ord, replace
inval_ord: all characters numeric; replaced as byte
(1272 missing values generated)

.         gen parti_initial=parti_initial_v 

.         collapse (max) vald (min) inval_ord, by(llkk parti_initial parti_initial_v llkk_2 ar partinamn lopnr)   

.         save "$gdat\temp_vald_old.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Data Extraction and Files\Data files\temp_vald_old.dta saved

.                 
.         * gör en vald-indikator
.         use "$gdat\temp_rel_nom_old.dta", clear

.         joinby lopnr llkk ar parti_initial using "\\micro.intra\Projekt\P0624$\P0624_Gem\Data Extraction and Files\Data files\temp_
> vald_old.dta", unmatched(both)

.         
.                 foreach var of varlist partikod{
  2.         destring `var' , replace force
  3.         }
partikod: all characters numeric; replaced as int
(3068 missing values generated)

.         
.         save "$gdat\temp_pol_old.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Data Extraction and Files\Data files\temp_pol_old.dta saved

.                 
.         use "nom_ko_9111.dta", clear

.         * Fixa korrekta listnummer för 1994
.         drop if ar == 1994
(57,163 observations deleted)

.         append using "2014\nom_ko_2014.dta"

.         
.         foreach var of varlist nrinom listnr ko_valkretskod{
  2.         destring `var' , replace force
  3.         }
nrinom: all characters numeric; replaced as byte
(64 missing values generated)
listnr: all characters numeric; replaced as int
(157 missing values generated)
ko_valkretskod: all characters numeric; replaced as byte

. 
.         append using "nom_ko_94"
(variable listnr was int, now double to accommodate using data's values)
(variable ko_valkretskod was byte, now double to accommodate using data's values)
(variable nrinom was byte, now double to accommodate using data's values)

.         replace ar=1994 if ar==.
(76,340 real changes made)

.                 destring llkk, replace force
llkk: all characters numeric; replaced as int

. 
. drop if ar==2011
(400 observations deleted)

. do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(606 real changes made)

. replace llkk = 1438 if llkk==1504
(253 real changes made)

. replace llkk = 1439 if llkk== 1507
(281 real changes made)

. replace llkk = 1440 if llkk==1521
(406 real changes made)

. replace llkk = 1441 if llkk== 1524
(783 real changes made)

. replace llkk = 1442 if llkk== 1527
(430 real changes made)

. replace llkk = 1443 if llkk== 1535
(136 real changes made)

. replace llkk = 1444 if llkk== 1602
(315 real changes made)

. replace llkk = 1445 if llkk==1603
(271 real changes made)

. replace llkk = 1446 if llkk== 1637
(229 real changes made)

. replace llkk = 1447 if llkk== 1643
(326 real changes made)

. replace llkk = 1452 if llkk== 1552
(242 real changes made)

. replace llkk = 1460 if llkk== 1560
(330 real changes made)

. replace llkk = 1461 if llkk== 1561
(252 real changes made)

. replace llkk = 1462 if llkk== 1562
(339 real changes made)

. replace llkk = 1463 if llkk== 1563
(566 real changes made)

. replace llkk = 1465 if llkk== 1565
(268 real changes made)

. replace llkk = 1466 if llkk== 1566
(321 real changes made)

. replace llkk = 1470 if llkk==1660
(494 real changes made)

. replace llkk = 1471 if llkk==1661
(373 real changes made)

. replace llkk = 1472 if llkk== 1662
(382 real changes made)

. replace llkk = 1473 if llkk== 1663
(336 real changes made)

. replace llkk = 1487 if llkk== 1580
(627 real changes made)

. replace llkk = 1488 if llkk== 1581
(681 real changes made)

. replace llkk = 1489 if llkk== 1582
(895 real changes made)

. replace llkk = 1490 if llkk== 1583
(1,188 real changes made)

. replace llkk = 1491 if llkk== 1584
(516 real changes made)

. replace llkk = 1492 if llkk== 1585
(309 real changes made)

. replace llkk = 1493 if llkk== 1680
(414 real changes made)

. replace llkk = 1494 if llkk== 1681
(611 real changes made)

. replace llkk = 1495 if llkk==1682
(355 real changes made)

. replace llkk = 1496 if llkk== 1683
(698 real changes made)

. replace llkk = 1497 if llkk== 1684
(288 real changes made)

. replace llkk = 1498 if llkk== 1685
(339 real changes made)

. replace llkk = 1499 if llkk== 1686
(656 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(243 real changes made)

. replace llkk = 643 if llkk==1623 
(242 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(289 real changes made)

. replace llkk =1257      if llkk==       1137
(432 real changes made)

. replace llkk =1270 if llkk==    1160    
(269 real changes made)

. replace llkk =1272      if llkk==       1162
(252 real changes made)

. replace llkk =1273      if llkk==       1163
(566 real changes made)

. replace llkk =1275 if llkk==    1165    
(223 real changes made)

. replace llkk =1276      if llkk==       1166
(310 real changes made)

. replace llkk =1277 if llkk==    1167    
(275 real changes made)

. replace llkk =1278 if llkk==    1168    
(437 real changes made)

. replace llkk =1290 if llkk==    1180    
(752 real changes made)

. replace llkk =1291      if llkk==       1181
(471 real changes made)

. replace llkk =1292      if llkk==       1182
(613 real changes made)

. replace llkk =1293      if llkk==       1183
(1,030 real changes made)

. 
end of do-file

.         drop if llkk==.
(0 observations deleted)

.         rename vald vald_n

.         save "$gdat\temp_rel_nom.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Data Extraction and Files\Data files\temp_rel_nom.dta saved

. 
.         use "valda_ko_9111.dta", clear

.         append using "2014\valda_ko_2014.dta"

.         drop if ar==2011
(17 observations deleted)

. 
.         destring llkk, replace force
llkk: all characters numeric; replaced as int

.         do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(172 real changes made)

. replace llkk = 1438 if llkk==1504
(82 real changes made)

. replace llkk = 1439 if llkk== 1507
(70 real changes made)

. replace llkk = 1440 if llkk==1521
(98 real changes made)

. replace llkk = 1441 if llkk== 1524
(102 real changes made)

. replace llkk = 1442 if llkk== 1527
(82 real changes made)

. replace llkk = 1443 if llkk== 1535
(41 real changes made)

. replace llkk = 1444 if llkk== 1602
(62 real changes made)

. replace llkk = 1445 if llkk==1603
(82 real changes made)

. replace llkk = 1446 if llkk== 1637
(70 real changes made)

. replace llkk = 1447 if llkk== 1643
(81 real changes made)

. replace llkk = 1452 if llkk== 1552
(74 real changes made)

. replace llkk = 1460 if llkk== 1560
(90 real changes made)

. replace llkk = 1461 if llkk== 1561
(82 real changes made)

. replace llkk = 1462 if llkk== 1562
(82 real changes made)

. replace llkk = 1463 if llkk== 1563
(102 real changes made)

. replace llkk = 1465 if llkk== 1565
(80 real changes made)

. replace llkk = 1466 if llkk== 1566
(82 real changes made)

. replace llkk = 1470 if llkk==1660
(98 real changes made)

. replace llkk = 1471 if llkk==1661
(82 real changes made)

. replace llkk = 1472 if llkk== 1662
(76 real changes made)

. replace llkk = 1473 if llkk== 1663
(82 real changes made)

. replace llkk = 1487 if llkk== 1580
(102 real changes made)

. replace llkk = 1488 if llkk== 1581
(122 real changes made)

. replace llkk = 1489 if llkk== 1582
(102 real changes made)

. replace llkk = 1490 if llkk== 1583
(152 real changes made)

. replace llkk = 1491 if llkk== 1584
(98 real changes made)

. replace llkk = 1492 if llkk== 1585
(82 real changes made)

. replace llkk = 1493 if llkk== 1680
(98 real changes made)

. replace llkk = 1494 if llkk== 1681
(102 real changes made)

. replace llkk = 1495 if llkk==1682
(90 real changes made)

. replace llkk = 1496 if llkk== 1683
(122 real changes made)

. replace llkk = 1497 if llkk== 1684
(66 real changes made)

. replace llkk = 1498 if llkk== 1685
(82 real changes made)

. replace llkk = 1499 if llkk== 1686
(102 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(70 real changes made)

. replace llkk = 643 if llkk==1623 
(70 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(82 real changes made)

. replace llkk =1257      if llkk==       1137
(90 real changes made)

. replace llkk =1270 if llkk==    1160    
(82 real changes made)

. replace llkk =1272      if llkk==       1162
(82 real changes made)

. replace llkk =1273      if llkk==       1163
(82 real changes made)

. replace llkk =1275 if llkk==    1165    
(70 real changes made)

. replace llkk =1276      if llkk==       1166
(90 real changes made)

. replace llkk =1277 if llkk==    1167    
(82 real changes made)

. replace llkk =1278 if llkk==    1168    
(98 real changes made)

. replace llkk =1290 if llkk==    1180    
(142 real changes made)

. replace llkk =1291      if llkk==       1181
(98 real changes made)

. replace llkk =1292      if llkk==       1182
(102 real changes made)

. replace llkk =1293      if llkk==       1183
(122 real changes made)

. 
end of do-file

.         gen vald=1

. 
.                 foreach var of varlist valgrund  ko_valkretskod llkk{
  2.         destring `var' , replace force
  3.         }
valgrund: all characters numeric; replaced as byte
(27070 missing values generated)
ko_valkretskod: all characters numeric; replaced as byte
llkk already numeric; no replace

.         
. joinby lopnr ko_valkretskod llkk ar partikod using "$gdat\temp_rel_nom.dta", unmatched(both)

.                 foreach var of varlist ripartikod partikod{
  2.         destring `var' , replace force
  3.         }
ripartikod: all characters numeric; replaced as int
(469710 missing values generated)
partikod: all characters numeric; replaced as int
(16 missing values generated)

. 
. egen tag_indarkrets=tag (lopnr ar ko_valkretskod )

. 
.         * summera personröster över valkrets och år  
.         bysort lopnr  ko_valkretskod ar: egen pers_roster_b= sum(antpersonrost)

.         gen pers_roster=pers_roster_b if tag_indarkrets==1
(37,968 missing values generated)

. 
.         * sätt vald=1 om vald i minst en valkrets
.         bysort  lopnr ar: egen vald_korr=max(vald)
(437,322 missing values generated)

.         
.         * sätt vald_lista=1 om man inte är personvald utan vald från en viss lista 
.         gen vald_lista= 1 if (valgrund ==1  | valgrund ==2  | valgrund ==5  | valgrund ==6 ) &vald==1
(510,352 missing values generated)

. 
.         * väljs slumpmässig observation för varje individ och år
.         egen tag_indar=tag (lopnr ar)

.         bysort   llkk ko_valkretskod partikod listnr ar: egen valda=sum(vald)

.         bysort   llkk ko_valkretskod partikod ar: egen valda_rank=rank(valda) ,field

.         bysort   llkk ko_valkretskod partikod ar: egen valda_rank1=max(valda) if valda_rank==1
(65,828 missing values generated)

.         bysort   llkk ko_valkretskod partikod ar: egen valda_rank2=max(valda) if valda_rank==2
(583,349 missing values generated)

. 
.         gen huvudlista_vk =1

.         replace huvudlista_vk=0 if valda_rank!=1 & ((valda_rank1>=(2*valda))|(valda==0 &valda_rank1>1))
(65,828 real changes made)

. 
.         gen nrinom_hl=nrinom if huvudlista_vk==1        
(66,002 missing values generated)

.         gen personval=1 if valgrund==1 |valgrund==5|valgrund==3
(564,555 missing values generated)

.  replace personval=0 if valgrund==2 |valgrund==6 |valgrund==4
(66,437 real changes made)

.  
.  gen nrinom_vikt=nrinom/valda
(53,653 missing values generated)

.         
.         gen valkrets =ko_valkretskod 

. replace valkrets=1 if valkrets==0
(232,333 real changes made)

. gen valar=ar

. 
. collapse (min)nrin* (max)  personval vald  (min) ripartikod  llkk (sum) pers_roster, by (partikod lopnr ar)

. drop if ar==2011
(0 observations deleted)

.         
.  bysort llkk ar partikod: egen rank_ind= rank (nrinom_vikt) , track
(16,561 missing values generated)

.  bysort llkk ar partikod: egen pers_sum= sum (pers_roster) 

.  gen pers_share_parti =pers_roster/pers_sum if ar>1997
(112,811 missing values generated)

.  
.         gen parti_initial = "M" if partikod==1
(312,687 missing values generated)

.         replace parti_initial = "S" if partikod ==2
(99,722 real changes made)

.         replace parti_initial = "F" if partikod ==3
(39,268 real changes made)

.         replace parti_initial = "C" if partikod ==4
(55,042 real changes made)

.         replace parti_initial = "V" if partikod ==5
(27,735 real changes made)

.         replace parti_initial = "G" if partikod ==55
(20,262 real changes made)

.         replace parti_initial = "B" if partikod ==110
(6,694 real changes made)

.         replace parti_initial = "G" if partikod ==55
(0 real changes made)

.         replace parti_initial = "K" if partikod ==68
(34,704 real changes made)

.         replace parti_initial = "N" if partikod ==170
(1,351 real changes made)

.         replace parti_initial = "L" if  parti_initial=="" & partikod !=.        
(27,893 real changes made)

. 
. 
. append using "$gdat\temp_pol_old.dta"
(label __MERGE already defined)

.         gen nom=1

. 
.         replace vald=0 if vald==.
(403,295 real changes made)

.         gen Person_LopNr= lopnr

.         gen valar = ar

.         duplicates tag lopnr ar, gen(test)

Duplicates in terms of lopnr ar

.          drop if test!=0 & vald==0
(2,549 observations deleted)

.         drop _merge test

.                 duplicates tag lopnr ar, gen(test)

Duplicates in terms of lopnr ar

.                 drop if test!=0 
(14 observations deleted)

.                 drop test

.                 ren Person p_id

.         save "$dat\mun politician data" , replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\mun politician data.dta saved

. 
. 
. ********************************
. *****    District and id     ***
. ********************************
.         
. use "\\micro.intra\Projekt\P0624$\P0624_Data\distrikt_0210.dta" , clear

. gen llkk= substr(llkkdddd,1,4)

. gen dist= substr(llkkdddd,5,4)

. drop llkkdddd 

. ren ar year

. ren lop p_id

. destring llkk dist , force replace
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(10,413 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

. save "$dat\dist p_id year.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\dist p_id year.dta saved

.  
. 
.  
. *************************
. *****    Property     ***
. *************************
. 
. odbc load, exec("SELECT * FROM Tab01_Fastighet") dsn("P0624") clear

. save "$dat\Fastigheter\fast_geo.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\fast_geo.dta saved

. 
. odbc load, exec("SELECT * FROM Tab06A_Avregdat") dsn("P0624") clear

. save "$dat\Fastigheter\fast_avregdat.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\fast_avregdat.dta saved

. 
. odbc load, exec("SELECT * FROM Tab08A_Areal") dsn("P0624") clear

. g temp_areal=_n

. save "$dat\Fastigheter\areal.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\areal.dta saved

. 
. 
. odbc load, exec("SELECT * FROM Tab55A_Entre") dsn("P0624") clear

. save "$dat\Fastigheter\entre.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\entre.dta saved

. 
. odbc load, exec("SELECT * FROM Tab55B_Lagenhet") dsn("P0624") clear

. g temp_lgh=_n

. gen lgh= Lghkat=="1" |  Lghkat=="9" 

. gen spec= Lghkat=="2" |  Lghkat=="4" 

. gen stud= Lghkat=="3"

. joinby RNPENTRE_RIDENTRE_LopNr using "$dat\Fastigheter\entre.dta", unmatched(both)

. sort RNPREGBY_RIDREGBY_LopNr temp_lgh

. drop temp_lgh

. collapse (sum) lgh spec stud  Boarea, by(RNPREGBY_RIDREGBY_LopNr)

. save "$dat\Fastigheter\lgh.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\lgh.dta saved

.  
. 
. odbc load, exec("SELECT * FROM Tab50A_Registerbyggnad") dsn("P0624") clear

. g temp_buildings=_n

. destring Byggtyp, replace force
Byggtyp: all characters numeric; replaced as byte
(5149204 missing values generated)

. gen b_multi=Byggtyp==33

. gen b_single =Byggtyp==30

. gen b_chain=Byggtyp==31 |Byggtyp==32

. gen b_two=Byggtyp==35

. 
. joinby RNPREGBY_RIDREGBY_LopNr using "$dat\Fastigheter\lgh.dta", unmatched(both)

. keep b_* Totboarea Totlokarea Byggnstat Byggar Ombyggar Nyregors Avregors  FNR_LopNr lgh spec stud Boarea temp_buildings

. save "$dat\Fastigheter\buildings.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\buildings.dta saved

. 
. ****koppla på fastigheter
. use "$dat\Fastigheter\fast_geo.dta", clear

. joinby FNR_LopNr  using "$dat\Fastigheter\fast_avregdat.dta", unmatched(both) 

. drop _merge

. 
. joinby FNR_LopNr  using "$dat\Fastigheter\buildings.dta", unmatched(both)

. gen avregar=yofd(dofc(Avregdat))
(10,214,471 missing values generated)

. drop _merge

. 
. joinby FNR_LopNr  using "$dat\Fastigheter\areal.dta", unmatched(master)

. destring Byggar, force replace
Byggar: all characters numeric; replaced as int
(8284563 missing values generated)

. egen area_basea  = rowtotal (Totboarea Totlokarea)

. egen area_base  = rowmax (area_basea Boarea)

. foreach type in single multi chain two{
  2. gen b_area_`type'= area_base   if b_`type'==1
  3. gen b_no_`type'=lgh  if b_`type'==1
  4. }
(8,404,201 missing values generated)
(8,518,677 missing values generated)
(10,799,661 missing values generated)
(10,802,908 missing values generated)
(10,661,115 missing values generated)
(10,662,612 missing values generated)
(10,935,436 missing values generated)
(10,936,009 missing values generated)

. drop area*

. gsort FNR_LopNr -Land -Totar temp_areal temp_buildings

. egen tag=tag (FNR_LopNr) 

. gen land_area=Land if tag==1
(7,626,933 missing values generated)

. replace land_area=Totar if Landar==0  & tag==1
(50,761 real changes made)

. drop _merge- Oskod temp*

. save "$dat\Fastigheter\fastbygg.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\Fastigheter\fastbygg.dta saved

. 
. foreach year in 2002 2006 2010 {
  2. use "$dat\Fastigheter\fastbygg.dta", clear 
  3. g temp=_n
  4. keep if Byggar<= `year' & Byggnstat=="1"
  5. ren  Valdist`year' valdist
  6. gen dist=substr(valdist, 5,4)
  7. gen llkk=substr(valdist, 1,4)
  8. destring dist llkk, replace force
  9. do "$do\mun code clean.do"
 10. sort  dist llkk temp
 11. drop temp*
 12. collapse (sum) b_* land lgh, by(dist llkk)
 13. gen year =  `year'
 14. drop if mi(dist)
 15. if `year'==2002 save "$dat\property.dta", replace
 16. else append using "$dat\property.dta"
 17. save "$dat\property.dta", replace
 18. }
(8,569,678 observations deleted)
(19 missing values generated)
(19 missing values generated)
dist: all characters numeric; replaced as int
(19 missing values generated)
llkk: all characters numeric; replaced as int
(19 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(5,324 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(1 observation deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\property.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\property.dta saved
(8,511,513 observations deleted)
(21 missing values generated)
(21 missing values generated)
dist: all characters numeric; replaced as int
(21 missing values generated)
llkk: all characters numeric; replaced as int
(21 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(5,384 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(1 observation deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\property.dta saved
(8,449,894 observations deleted)
(3 missing values generated)
(3 missing values generated)
dist: all characters numeric; replaced as int
(3 missing values generated)
llkk: all characters numeric; replaced as int
(3 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(1 observation deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\property.dta saved

. 
. 
. 
. 
.  
. **********************************************
. *****   Match district and coordinates     ***
. **********************************************
. 
. foreach year in 2002 2006 2010{
  2. odbc load, exec("SELECT * FROM Tab01_Fastighet") dsn("P0624") clear
  3. keep  FNR_LopNr Valdist`year' RutaRT
  4. drop if Valdist==""
  5. joinby FNR_LopNr  using "$dat\Fastigheter\buildings.dta", unmatched(master)
  6. drop temp_buildings
  7. egen fast=tag (FNR_LopNr)
  8. 
. gen xcoord=substr(Ruta,8,7)
  9. gen ycoord=substr(Ruta,1,7)
 10. 
. destring ycoord xcoord, replace force
 11.   
. replace ycoord=int(ycoord/500)*500
 12. replace xcoord=int(xcoord/500)*500
 13. 
. collapse (sum) lgh fast, by (Valdist ycoor xcoor)
 14.  
.  bysort ycoor xcoor: egen max_lgh=max(lgh)
 15.  keep if lgh==max_lgh
 16.   bysort ycoor xcoor: egen max_fast=max(fast)
 17.  keep if fast==max_fast
 18.  sort ycoord xcoord Valdist*
 19.  duplicates drop ycoor xcoor, force
 20.  keep ycoor xcoor Valdist
 21. 
.  save "$dat\xy_valdist_`year'.dta", replace
 22.  }
(1,435,332 observations deleted)
ycoord: all characters numeric; replaced as long
xcoord: all characters numeric; replaced as long
(2,375,963 real changes made)
(2,373,583 real changes made)
(28,573 observations deleted)
(3,617 observations deleted)

Duplicates in terms of ycoord xcoord

(1,416 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\xy_valdist_2002.dta saved
(1,435,329 observations deleted)
ycoord: all characters numeric; replaced as long
xcoord: all characters numeric; replaced as long
(2,375,966 real changes made)
(2,373,593 real changes made)
(27,716 observations deleted)
(3,433 observations deleted)

Duplicates in terms of ycoord xcoord

(1,352 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\xy_valdist_2006.dta saved
(1,435,337 observations deleted)
ycoord: all characters numeric; replaced as long
xcoord: all characters numeric; replaced as long
(2,375,981 real changes made)
(2,373,599 real changes made)
(26,756 observations deleted)
(3,200 observations deleted)

Duplicates in terms of ycoord xcoord

(1,257 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\xy_valdist_2010.dta saved

.  
. 
.  
.  
.  
. *************************
. *****    Network      ***
. *************************
. 
. *******  coll   ****
.         odbc load, exec("select p_id=Person_LopNr, cfar=CfarNr_LopNr, peorg=Peorgnr_LopNr from P0624_Lisa_2002") dsn("P0624") clear

.         gen year=2002

.         save "$dat\coll_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\coll_neighbours.dta saved

.         
.         clear

.                 odbc load, exec("select p_id=Person_LopNr, cfar=CfarNr_LopNr, peorg=Peorgnr_LopNr from P0624_Lisa_2006") dsn("P0624
> "), 

.                         gen year=2006

.                         append using "$dat\coll_neighbours.dta"

.                         save "$dat\coll_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\coll_neighbours.dta saved

.                         
.                                 clear

.                 odbc load, exec("select p_id=Person_LopNr, cfar=CfarNr_LopNr, peorg=Peorgnr_LopNr from P0624_Lisa_2010") dsn("P0624
> ")

.                         gen year=2010

.                         append using "$dat\coll_neighbours.dta"

.                         save "$dat\coll_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\coll_neighbours.dta saved

.                         
.                         joinby  p_id year using "$dat\dist p_id year.dta", unmatched(none)

.                         
.                         gen count=1

.                         bysort year cfar peorg: egen wp_size= sum(count) if  cfar!=. & peorg!=.
(8,536,949 missing values generated)

.                         bysort dist year cfar peorg: egen wp_neigh= sum(count)  if  cfar!=. & peorg!=.
(8,536,949 missing values generated)

.                         replace wp_neigh= wp_neigh-1
(12,736,397 real changes made)

.                         
.                         gen valar=year

.         joinby p_id valar using "$dat\mun politician data.dta", unmatched(none) 

.         
.         gen parti_low=lower(parti_initial)

.         
. *generarar variabel för antalter nominerade och valda från varje parti
. foreach parti in b m c k f l g s v{
  2. gen vald_`parti'= vald==1 & parti_low =="`parti'" 
  3. gen vald_ab5coll_`parti'= vald==1 & parti_low =="`parti'" & wp_neigh>=5 & wp_neigh!=.
  4. gen vald_bel5coll_`parti'= vald==1 & parti_low =="`parti'" & (wp_neigh<5 |  wp_neigh==.)
  5. gen vald_coll_`parti'= vald==1 & parti_low =="`parti'" & wp_neigh>=1 & wp_neigh!=.
  6. gen vald_nocoll_`parti'= vald==1 & parti_low =="`parti'" & (wp_neigh<1 |  wp_neigh==.)
  7.  }

. 
.  do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  collapse (sum) vald vald_*  , by (llkk dist year)  

. 
. gen valar=year

. joinby llkk valar using "$dat\kommundata.dta", unmatched(master)

.         foreach gr in vald{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom_`gr'_`pow'=sum(`gr'_`pow')
  6.                 drop `gr'_`pow'
  7.  }
  8.  
.         }
(734 missing values generated)
(734 missing values generated)

.         foreach gr in vald_ab5coll vald_bel5coll vald_coll vald_nocoll{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom=sum(`gr'_`pow')
  6. * calculate share of group living in the district
.         gen sh_`gr'_`pow' =`gr'_`pow' /kom
  7.         gen shalt_`gr'_`pow' =`gr'_`pow' /kom_vald_`pow'
  8.         drop kom
  9.  } 
 10.  gen diff_maj_min_`gr'=sh_`gr'_maj-sh_`gr'_min
 11.   gen diffalt_maj_min_`gr'=shalt_`gr'_maj-shalt_`gr'_min
 12.  drop sh_`gr'_maj  sh_`gr'_min shalt_`gr'_maj  shalt_`gr'_min `gr'_maj `gr'_min
 13.  }
(734 missing values generated)
(734 missing values generated)
(1,556 missing values generated)
(1,551 missing values generated)
(928 missing values generated)
(790 missing values generated)
(1,750 missing values generated)
(1,607 missing values generated)
(734 missing values generated)
(734 missing values generated)
(1,551 missing values generated)
(1,551 missing values generated)
(792 missing values generated)
(790 missing values generated)
(1,609 missing values generated)
(1,607 missing values generated)
(734 missing values generated)
(734 missing values generated)
(1,551 missing values generated)
(1,551 missing values generated)
(790 missing values generated)
(790 missing values generated)
(1,607 missing values generated)
(1,607 missing values generated)
(734 missing values generated)
(734 missing values generated)
(1,558 missing values generated)
(1,551 missing values generated)
(812 missing values generated)
(790 missing values generated)
(1,636 missing values generated)
(1,607 missing values generated)

.  
. 
. keep year llkk dist diff*

. save "$dat\coll_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\coll_neighbours.dta saved

. 
.         
. 
. ***** timesave *****
.         
. odbc load, exec("SELECT * FROM Geo") dsn("P0624") clear

. keep X* Y* Lop

. ren Lop p_id

. joinby p_id using "$dat\pol_id_complete.dta" , unmatched(none)

. duplicates drop p_id, force

Duplicates in terms of p_id

(1,284 observations deleted)

. reshape long XKOORD_@ YKOORD_@, i(p_id) j(year)
(j = 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 200
> 4 2005 2006 2007 2008 2009 2010 2011 2012)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations          236,803   ->   8,051,302   
Number of variables                  69   ->   4           
j variable (34 values)                    ->   year
xij variables:
XKOORD_1979 XKOORD_1980 ... XKOORD_2012   ->   XKOORD_
YKOORD_1979 YKOORD_1980 ... YKOORD_2012   ->   YKOORD_
-----------------------------------------------------------------------------

. 
. sort p_id year

. 
. gen years_same=XK==XK[_n-1] & YK==YK[_n-1] if p_id[_n-1]==p_id
(236,803 missing values generated)

. 
. forvalues years=2/20{
  2.         replace years_same=`years' if years_same==`years'-1 & XK[_n-`years'] & YK==YK[_n-`years'] & p_id[_n-`years']==p_id
  3. }
(6,222,865 real changes made)
(5,592,696 real changes made)
(5,050,895 real changes made)
(4,575,611 real changes made)
(4,153,102 real changes made)
(3,774,109 real changes made)
(3,432,082 real changes made)
(3,121,626 real changes made)
(2,838,858 real changes made)
(2,580,111 real changes made)
(2,342,441 real changes made)
(2,123,886 real changes made)
(1,922,422 real changes made)
(1,736,468 real changes made)
(1,565,243 real changes made)
(1,407,340 real changes made)
(1,261,415 real changes made)
(1,126,381 real changes made)
(1,001,596 real changes made)

. 
.                         gen valar=year

. 
.         joinby p_id valar using "$dat\mun politician data.dta", unmatched(none) 

. 
.         gen parti_low=lower(parti_initial)
(15 missing values generated)

.         
. *generarar variabel för antalter nominerade och valda från varje parti
. foreach parti in b m c k f l g s v{
  2. gen vald_`parti'= vald==1 & parti_low =="`parti'" 
  3. gen vald_ab5sm_`parti'= vald==1 & parti_low =="`parti'" & years_same>=5 & years_same!=.
  4. gen vald_bel5sm_`parti'= vald==1 & parti_low =="`parti'" & (years_same<5 .)
  5. gen vald_ab10sm_`parti'= vald==1 & parti_low =="`parti'" & years_same>=10 & years_same!=.
  6. gen vald_bel10sm_`parti'= vald==1 & parti_low =="`parti'" & (years_same<10 .)
  7. gen vald_ab15sm_`parti'= vald==1 & parti_low =="`parti'" & years_same>=15 & years_same!=.
  8. gen vald_bel15sm_`parti'= vald==1 & parti_low =="`parti'" & (years_same<15 .)
  9.  }

.  
. joinby  p_id year using "$dat\dist p_id year.dta", unmatched(none)

. do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  collapse (sum) vald vald_*  , by (llkk dist year)

.  
.  
. 
. gen valar=year

. joinby llkk valar using "$dat\kommundata.dta", unmatched(master)

.         foreach gr in vald{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  
.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom_`gr'_`pow'=sum(`gr'_`pow')
  6.                 drop `gr'_`pow'
  7.  }
  8.  
.         }
(760 missing values generated)
(760 missing values generated)

.         foreach gr in vald_ab5sm vald_bel5sm vald_ab10sm vald_bel10sm vald_ab15sm vald_bel15sm{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom=sum(`gr'_`pow')
  6. * calculate share of group living in the district
.         gen sh_`gr'_`pow' =`gr'_`pow' /kom
  7.         gen shalt_`gr'_`pow' =`gr'_`pow' /kom_vald_`pow'
  8.         drop kom
  9.  } 
 10.  gen diff_maj_min_`gr'=sh_`gr'_maj-sh_`gr'_min
 11.   gen diffalt_maj_min_`gr'=shalt_`gr'_maj-shalt_`gr'_min
 12.  drop sh_`gr'_maj  sh_`gr'_min shalt_`gr'_maj  shalt_`gr'_min `gr'_maj `gr'_min
 13.  }
(760 missing values generated)
(760 missing values generated)
(1,609 missing values generated)
(1,609 missing values generated)
(818 missing values generated)
(818 missing values generated)
(1,667 missing values generated)
(1,667 missing values generated)
(760 missing values generated)
(760 missing values generated)
(1,732 missing values generated)
(1,609 missing values generated)
(1,105 missing values generated)
(818 missing values generated)
(2,060 missing values generated)
(1,667 missing values generated)
(760 missing values generated)
(760 missing values generated)
(1,609 missing values generated)
(1,609 missing values generated)
(818 missing values generated)
(818 missing values generated)
(1,667 missing values generated)
(1,667 missing values generated)
(760 missing values generated)
(760 missing values generated)
(1,624 missing values generated)
(1,609 missing values generated)
(858 missing values generated)
(818 missing values generated)
(1,722 missing values generated)
(1,667 missing values generated)
(760 missing values generated)
(760 missing values generated)
(1,609 missing values generated)
(1,609 missing values generated)
(828 missing values generated)
(818 missing values generated)
(1,677 missing values generated)
(1,667 missing values generated)
(760 missing values generated)
(760 missing values generated)
(1,609 missing values generated)
(1,609 missing values generated)
(829 missing values generated)
(818 missing values generated)
(1,678 missing values generated)
(1,667 missing values generated)

.  
.  keep year llkk dist diff*

.  save "$dat\timesame_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\timesame_neighbours.dta saved

. 
. 
.  
. *****  relatives ****
. 
.         use "$dat\mun politician data.dta", clear

.         keep if valar>2000 & valar<2011 & vald==1
(493,872 observations deleted)

. g year=valar

.         save "$dat\relatives_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\relatives_neighbours.dta saved

.         clear

.         odbc load, exec("select * from BioForaldrar") dsn("P0624")

.         ren LopNr p_id

.         joinby p_id using "$dat\relatives_neighbours.dta", unmatched (using)

.         
.         ren p_id pol_id

.         ren LopNr_BioMor  p_id

.         ren llkk llkk_pol

.         drop _merge

.                 joinby  p_id year using "$dat\dist p_id year.dta", unmatched(master)

.                 drop  _merge vdnamn

.                 ren llkk llkk_mo

.                 ren dist dist_mo

.                 drop p_id

.                 ren     LopNr_BioFar  p_id

. 
.                 joinby  p_id year using "$dat\dist p_id year.dta", unmatched(master)

.                 drop _merge vdnamn

.                 ren llkk llkk_fa

.                 ren dist dist_fa

.                                         drop p_id

.                                         
.                                         ren pol_id p_id

.                                                 save "$dat\relatives_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\relatives_neighbours.dta saved

.         clear

.         odbc load, exec("select * from BioSyskon") dsn("P0624")

.         ren LopNr p_id

.         joinby p_id using "$dat\relatives_neighbours.dta", unmatched (using)

.         
.         ren p_id pol_id

.         
.         ren LopNr_BioSyskon  p_id

. 
.         drop _merge

.                 joinby  p_id year using "$dat\dist p_id year.dta", unmatched(master)

.                 drop _merge vdnamn

.                 ren llkk llkk_sib

.                 ren dist dist_sib

.                 drop p_id

.                 ren pol_id p_id 

.                                 joinby  p_id year using "$dat\dist p_id year.dta", unmatched(master)

.                                 
.                                 
.                                 gen same_mo=dist==dist_mo & llkk==llkk_mo

.                                 gen same_fa=dist==dist_fa & llkk==llkk_fa

.                                 gen same_sib=dist==dist_sib & llkk==llkk_sib

.                                 
.                         bysort p_id year : egen same_sib_sum=sum(same_sib)

.                         gen same_rel= same_fa+ same_mo+ same_sib_sum

.                         duplicates drop p_id year, force

Duplicates in terms of p_id year

(45,357 observations deleted)

.                         
.                         
.         gen parti_low=lower(parti_initial)

.         
. *generarar variabel för antalter nominerade och valda från varje parti
. foreach parti in b m c k f l g s v{
  2. gen vald_`parti'= vald==1 & parti_low =="`parti'" 
  3. gen vald_rel_`parti'= vald==1 & parti_low =="`parti'" & same_rel>=1 & same_rel!=.
  4. gen vald_norell_`parti'= vald==1 & parti_low =="`parti'" & (same_rel<1 |  same_rel==.)
  5. 
.  }

.  
.  do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  collapse (sum) vald vald_*  , by (llkk dist year)

.  
. gen valar=year

. joinby llkk valar using "$dat\kommundata.dta", unmatched(master)

.         foreach gr in vald{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom_`gr'_`pow'=sum(`gr'_`pow')
  6.                 drop `gr'_`pow'
  7.  }
  8.  
.         }
(523 missing values generated)
(523 missing values generated)

.         foreach gr in vald_rel vald_norell{
  2.  gen `gr'_maj =mmaj2*`gr'_m +  cmaj2*`gr'_c +  fpmaj2*`gr'_f + kdmaj2*`gr'_k + mpmaj2*`gr'_g + smaj2*`gr'_s + vmaj2*`gr'_v
  3.  gen `gr'_min= (`gr'_m + `gr'_c + `gr'_f + `gr'_k + `gr'_g + `gr'_s + `gr'_v)-`gr'_maj
  4.  
.  foreach pow in maj min{
  5.                 bysort llkk year:  egen kom=sum(`gr'_`pow')
  6.                 
. * calculate share of group living in the district
.         gen sh_`gr'_`pow' =`gr'_`pow' /kom
  7.         gen shalt_`gr'_`pow' =`gr'_`pow' /kom_vald_`pow'
  8.         drop kom
  9.  } 
 10.  gen diff_maj_min_`gr'=sh_`gr'_maj-sh_`gr'_min
 11.   gen diffalt_maj_min_`gr'=shalt_`gr'_maj-shalt_`gr'_min
 12.  drop sh_`gr'_maj  sh_`gr'_min shalt_`gr'_maj  shalt_`gr'_min `gr'_maj `gr'_min
 13.  }
(523 missing values generated)
(523 missing values generated)
(1,467 missing values generated)
(1,183 missing values generated)
(1,200 missing values generated)
(570 missing values generated)
(2,102 missing values generated)
(1,230 missing values generated)
(523 missing values generated)
(523 missing values generated)
(1,183 missing values generated)
(1,183 missing values generated)
(570 missing values generated)
(570 missing values generated)
(1,230 missing values generated)
(1,230 missing values generated)

.  
. keep year llkk dist diff*

. save "$dat\relatives_neighbours.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\relatives_neighbours.dta saved

. 
.         
. 
. ***************************
. ***** Election results  ***
. ***************************     
. ** data on election results from Valmyndigheten 2002, 2006, 2010***
. 
. use "$dat\parl dist 2010.dta" , clear

. drop llkk

. ren om lan

. tostring lan kom , replace force
lan was byte now str2
kom was byte now str2

. forvalues n=1/9{
  2. replace kom="0`n'" if  kom=="`n'"
  3. }
(32 real changes made)
(20 real changes made)
(7 real changes made)
(17 real changes made)
(26 real changes made)
(2 real changes made)
(20 real changes made)
(0 real changes made)
(21 real changes made)

. egen llkk=concat (lan kom)

. destring llkk, force replace
llkk: all characters numeric; replaced as int

. 
. joinby llkk dist using "$dat\mun dist 2010.dta", unmatched(both) _merge(_merge)

. 
. 
. foreach p in m c f k s v g b{
  2. 
. replace  rost`p'=0 if rost`p'==.
  3. replace  rostr`p'=0 if rostr`p'==.
  4.  gen vsr_`p'=rostr`p'/rostrgil
  5.  gen vsm_`p'=rost`p'/rostgil
  6.  ren  rost`p' rostm`p'
  7.  }
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)

. gen part_r=rostrgil /rostrber
(395 missing values generated)

. gen part_kr=rostgil /rostber
(395 missing values generated)

.  
.  ren rostrgil rostr_gil 

.  ren rostgil rostm_gil

.  ren rostber rostm_ber

.  ren valdistriktnam vdnamn

.  keep llkk dist vsr* vsm* part* vdnamn rostm* rostr*

.  gen year=2010

.  gen valar=2010

. 
. 
. do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  save "$temp\dist_election_2010.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\temp\dist_election_2010.dta saved

. 
.  use "$dat\roster parti distrikt alla val 2006.dta" , clear

. ren VALTYP val

. ren VALDIST dist

. 
. tostring LAN KOM , replace force
LAN was byte now str2
KOM was byte now str2

. forvalues n=1/9{
  2. replace KOM="0`n'" if  KOM=="`n'"
  3. }
(1,228 real changes made)
(739 real changes made)
(246 real changes made)
(836 real changes made)
(953 real changes made)
(68 real changes made)
(681 real changes made)
(0 real changes made)
(745 real changes made)

. 
. egen llkk=concat( LAN KOM)

. destring llkk, force replace
llkk: all characters numeric; replaced as int

. ren TAL_ROST rost

. 
. replace val=strlower(val)
(237,951 real changes made)

. gen parti_initial="m" if FORKORTN=="M"
(219,464 missing values generated)

. replace parti_initial="b" if FORKORTN=="SD"
(18,242 real changes made)

. replace parti_initial="f" if FORKORTN=="FP"
(18,465 real changes made)

. replace parti_initial="c" if FORKORTN=="C"
(18,471 real changes made)

. replace parti_initial="g" if FORKORTN=="MP"
(18,443 real changes made)

. replace parti_initial="s" if FORKORTN=="S"
(18,489 real changes made)

. replace parti_initial="v" if FORKORTN=="V"
(18,452 real changes made)

. replace parti_initial="k" if FORKORTN=="KD"
(18,455 real changes made)

. replace parti_initial="o" if FORKORTN=="BLANK" | FORKORTN=="Og"
(18,390 real changes made)

. replace parti_initial="l" if parti_initial==""
(72,057 real changes made)

. drop if parti_initial =="o"
(18,390 observations deleted)

. 
. collapse (sum) rost , by(val llkk  dist parti_initial)

. 
. reshape wide rost@,j(val) i( llkk  dist parti_initial) string
(j = k l r)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations          162,771   ->   54,628      
Number of variables                   5   ->   6           
j variable (3 values)               val   ->   (dropped)
xij variables:
                                   rost   ->   rostk rostl rostr
-----------------------------------------------------------------------------

. ren rostk rostm

. 
. foreach var in rostm rostl rostr{
  2. bysort llkk dist: egen `var'_gil=sum(`var')
  3. }

. reshape wide rostr@ rostm@ rostl@,j( parti_initial) i( llkk  dist rostm_gil rostl_gil rostr_gil) string
(j = b c f g k l m s v)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations           54,628   ->   6,073       
Number of variables                   9   ->   32          
j variable (9 values)     parti_initial   ->   (dropped)
xij variables:
                                  rostr   ->   rostrb rostrc ... rostrv
                                  rostm   ->   rostmb rostmc ... rostmv
                                  rostl   ->   rostlb rostlc ... rostlv
-----------------------------------------------------------------------------

. 
. 
. foreach p in m c f k s v g b l{
  2. 
. 
. replace  rostm`p'=0 if rostm`p'==.
  3. replace  rostr`p'=0 if rostr`p'==.
  4. 
. 
.  gen vsr_`p'=rostr`p'/rostr_gil
  5.  gen vsm_`p'=rostm`p'/rostm_gil
  6.  replace vsr_`p'=0  if  vsr_`p'==. & rostr_gil!=.
  7.  replace vsm_`p'=0  if  vsm_`p'==. & rostm_gil!=.
  8.  }
(1 real change made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(7 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(14 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(22 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(24 real changes made)
(5 real changes made)
(0 real changes made)
(0 real changes made)
(32 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(122 real changes made)
(31 real changes made)
(0 real changes made)
(0 real changes made)
(268 real changes made)
(14 real changes made)
(0 real changes made)
(0 real changes made)

. 
.  keep llkk dist vsr* vsm*  rostr* rostm*

.  gen year=2006

.  gen valar=2006

.  do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  save "$temp\dist_election_2006", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\temp\dist_election_2006.dta saved

.  
.  
.  use "$dat\roster parti distrikt alla val 2002.dta" , clear

. ren VALTYP val

. ren VALDIST dist

. tostring LAN KOM , replace force
LAN was byte now str2
KOM was byte now str2

. forvalues n=1/9{
  2. replace KOM="0`n'" if  KOM=="`n'"
  3. }
(1,034 real changes made)
(629 real changes made)
(264 real changes made)
(769 real changes made)
(906 real changes made)
(132 real changes made)
(603 real changes made)
(0 real changes made)
(805 real changes made)

. egen llkk=concat( LAN KOM)

. destring llkk, force replace
llkk: all characters numeric; replaced as int

. ren TAL_ROST rost

. 
. replace val=strlower(val)
(215,325 real changes made)

. gen parti_initial="m" if FORKORTN=="M"
(196,475 missing values generated)

. replace parti_initial="b" if FORKORTN=="SD"
(12,196 real changes made)

. replace parti_initial="f" if FORKORTN=="FP"
(18,817 real changes made)

. replace parti_initial="c" if FORKORTN=="C"
(18,830 real changes made)

. replace parti_initial="g" if FORKORTN=="MP"
(18,781 real changes made)

. replace parti_initial="s" if FORKORTN=="S"
(18,871 real changes made)

. replace parti_initial="v" if FORKORTN=="V"
(18,836 real changes made)

. replace parti_initial="k" if FORKORTN=="KD"
(18,827 real changes made)

. replace parti_initial="o" if FORKORTN=="BLANK" | FORKORTN=="Og"
(0 real changes made)

. replace parti_initial="l" if parti_initial==""
(71,317 real changes made)

. drop if parti_initial =="o"
(0 observations deleted)

. 
. collapse (sum) rost , by(val llkk  dist parti_initial)

. 
. reshape wide rost@,j(val) i( llkk  dist parti_initial) string
(j = k l r)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations          161,900   ->   55,988      
Number of variables                   5   ->   6           
j variable (3 values)               val   ->   (dropped)
xij variables:
                                   rost   ->   rostk rostl rostr
-----------------------------------------------------------------------------

. ren rostk rostm

. 
. foreach var in rostm rostl rostr{
  2. bysort llkk dist: egen `var'_gil=sum(`var')
  3. 
. }

. reshape wide rostr@ rostm@ rostl@,j( parti_initial) i( llkk  dist rostm_gil rostl_gil rostr_gil) string
(j = b c f g k l m s v)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations           55,988   ->   6,266       
Number of variables                   9   ->   32          
j variable (9 values)     parti_initial   ->   (dropped)
xij variables:
                                  rostr   ->   rostrb rostrc ... rostrv
                                  rostm   ->   rostmb rostmc ... rostmv
                                  rostl   ->   rostlb rostlc ... rostlv
-----------------------------------------------------------------------------

. 
. foreach p in m c f k s v g b l{
  2. 
. replace  rostm`p'=0 if rostm`p'==.
  3. replace  rostr`p'=0 if rostr`p'==.
  4.  gen vsr_`p'=rostr`p'/rostr_gil
  5.  gen vsm_`p'=rostm`p'/rostm_gil
  6.  replace vsr_`p'=0  if  vsr_`p'==. & rostr_gil!=.
  7.  replace vsm_`p'=0  if  vsm_`p'==. & rostm_gil!=.
  8.  }
(11 real changes made)
(2 real changes made)
(0 real changes made)
(0 real changes made)
(10 real changes made)
(13 real changes made)
(0 real changes made)
(0 real changes made)
(25 real changes made)
(9 real changes made)
(0 real changes made)
(0 real changes made)
(26 real changes made)
(5 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(20 real changes made)
(4 real changes made)
(0 real changes made)
(0 real changes made)
(58 real changes made)
(9 real changes made)
(0 real changes made)
(0 real changes made)
(3,161 real changes made)
(414 real changes made)
(0 real changes made)
(0 real changes made)
(14 real changes made)
(21 real changes made)
(0 real changes made)
(0 real changes made)

. 
.  keep llkk dist vsr* vsm* rostm* rostr* rostr_gil rostm_gil

.  gen year=2002

.  gen valar=2002

.  do "$do\mun code clean.do" 

. 
. replace llkk = 331 if llkk==1917
(11 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file

.  save "$temp\dist_election_2002.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\temp\dist_election_2002.dta saved

.  append using "$temp\dist_election_2006.dta"

.  append using "$temp\dist_election_2010.dta"

. save "$dat\dist_election.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\dist_election.dta saved

.         
.         
. *************************
. ***** House prices    ***
. *************************
. 
. 
. use "$dat\all_price_transform", clear // year 2005-2014

. drop id

. duplicates drop // 0 obs

Duplicates in terms of all variables

(0 observations are duplicates)

. g temp=_n

. ****************************************************
. ** Drop if does not look like residential housing **
. ****************************************************
. 
. drop if ad_year>year & !mi(ad_year) // 400 obs 
(414 observations deleted)

. 
. ren price_per_sq_meter price_sqm

. destring price_sqm, replace 
price_sqm: all characters numeric; replaced as long
(47097 missing values generated)

. g price_sqm2=contract_price/living_area if !mi(living_area) & !mi(contract_price) & living_area!=0 & contract_price!=0
(47,085 missing values generated)

. replace price_sqm2=round(price_sqm2)
(1,146,074 real changes made)

. replace price_sqm=. if price_sqm<500 & !mi(price_sqm) 
(1,493 real changes made, 1,493 to missing)

. replace price_sqm=. if price_sqm>200000 & !mi(price_sqm) 
(99 real changes made, 99 to missing)

. replace price_sqm=price_sqm2 if mi(price_sqm) 
(1,606 real changes made)

. drop price_sqm2

. 
. drop if housing_category=="T" //plot 11 000 obs, only include house+summer house+apartments
(10,775 observations deleted)

. drop if mi(price_sqm) // 36,000 obs 
(36,320 observations deleted)

. drop if price_sqm<500 
(1,472 observations deleted)

. drop if price_sqm>200000 // 70 obs
(97 observations deleted)

. 
. ******************************************************************************
. *drop observations with more than 1 km between mstat- and google-coordinates
. *******************************************************************************
. * Double checked coordinates and adresses with google only exists for observations with coordinates, adress and county information 
> in maklar data
. ren location_wgs84_geopt_lon lon_wgs84

. ren location_wgs84_geopt_lat lat_wgs84

. ren google_geometry_location_lon google_lon_wgs84

. ren google_geometry_location_lat google_lat_wgs84

. ren location_rt90_geopt_lat lat_rt90

. ren location_rt90_geopt_lon lon_rt90

. 
. tab year if google_min_dist_km>=1 & !mi(google_min_dist_km) // more than 1 km off 34 000 oba, overrepresented for summer house 

       year |      Freq.     Percent        Cum.
------------+-----------------------------------
       2005 |      3,754       12.45       12.45
       2006 |      3,990       13.23       25.69
       2007 |      4,042       13.41       39.09
       2008 |      3,076       10.20       49.30
       2009 |      2,617        8.68       57.98
       2010 |      2,808        9.31       67.29
       2011 |      1,732        5.74       73.04
       2012 |      2,131        7.07       80.10
       2013 |      2,441        8.10       88.20
       2014 |      3,557       11.80      100.00
------------+-----------------------------------
      Total |     30,148      100.00

. drop if google_min_dist_km>=1 & !mi(google_min_dist_km)
(30,148 observations deleted)

. 
. *check that coordinates are within Sweden
. sum lon_rt90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    lon_rt90 |  1,256,219     1490004    145379.1    1222693    1880348

. sum google_lon_rt90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
google_lo~90 |  1,184,747     1490087    145485.8    1223168    1861278

. sum lat_rt90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
    lat_rt90 |  1,256,219     6520682    226150.1    6100200    7608978

. sum google_lat_rt90

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
google_la~90 |  1,184,747     6519558    225408.3    6137097    7608977

. 
. replace lat_rt90= google_lat_rt90 if google_min_dist_km<1 & google_min_dist_km>0.1 // replace with google coordinates 67000 obs
(65,621 real changes made)

. replace lon_rt90= google_lon_rt90 if google_min_dist_km<1 & google_min_dist_km>0.1 
(65,666 real changes made)

. 
. ***********************
. *** Check duplicates **
. ***********************
. * duplicats with the same contract date, address, and price 
. * could be new production, or multiple apartments in same building, but could also be error due to information reported from differ
> ent sources, usually just 1 dup, looks like it has additional info from the ad 
. 
. duplicates tag  formatted_address municipality plot_area living_area contract_price price_sqm contract_date housing_category apartm
> ent_number apartment_floor, g(dup)

Duplicates in terms of formatted_address municipality plot_area living_area contract_price price_sqm contract_date housing_category
    apartment_number apartment_floor

. tab dup // 4 %, only 3 & of them are new production

        dup |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |  1,211,491       96.00       96.00
          1 |     47,754        3.78       99.79
          2 |      1,635        0.13       99.92
          3 |        392        0.03       99.95
          4 |        235        0.02       99.97
          5 |        120        0.01       99.97
          6 |         84        0.01       99.98
          7 |         40        0.00       99.98
          8 |         27        0.00       99.99
          9 |         40        0.00       99.99
         10 |         22        0.00       99.99
         11 |         24        0.00       99.99
         13 |         14        0.00       99.99
         14 |         15        0.00      100.00
         15 |         32        0.00      100.00
         18 |         19        0.00      100.00
------------+-----------------------------------
      Total |  1,261,944      100.00

. drop dup

. sort  formatted_address municipality plot_area living_area contract_price price_sqm   contract_date housing_category apartment_numb
> er apartment_floor  lat_rt90 lon_rt90 temp

. duplicates drop   formatted_address municipality plot_area living_area contract_price price_sqm contract_date housing_category apar
> tment_number apartment_floor, force

Duplicates in terms of formatted_address municipality plot_area living_area contract_price price_sqm contract_date housing_category
    apartment_number apartment_floor

(25,833 observations deleted)

. 
. ********************************
. *** Create some new variables **
. ********************************
. 
. drop apart* 

. g apartment=(housing_category=="B") if  !mi(housing_category)
(23,911 missing values generated)

. gen sold_objects=1

. 
. 
. foreach x in price_sqm   sold_objects {
  2.         gen  `x'_new=  `x' if  new_production ==1
  3.         gen  `x'_old=  `x' if  new_production ==0
  4.         gen  `x'_a=  `x' if housing_category=="B" & new_production ==0
  5.         gen  `x'_h=  `x' if housing_category=="V" & new_production ==0
  6. }
(1,210,376 missing values generated)
(100,684 missing values generated)
(607,542 missing values generated)
(818,341 missing values generated)
(1,210,376 missing values generated)
(100,684 missing values generated)
(607,542 missing values generated)
(818,341 missing values generated)

. 
. 
. 
. 
. ***********************************************
. ** Create 500 m sq (coordinates=left corner) **
. ***********************************************
. 
. g xcoord= lat_rt90
(5,429 missing values generated)

. g ycoord= lon_rt90
(5,429 missing values generated)

. replace ycoord=int(ycoord/500)*500
(1,227,997 real changes made)

. replace xcoord=int(xcoord/500)*500
(1,227,980 real changes made)

. 
. 
. gen electionperiod=1998 if year>1999 & year<2003
(1,236,111 missing values generated)

. replace  electionperiod=2002 if year>2002 & year<2007
(224,483 real changes made)

. replace  electionperiod=2006 if year>2006 & year<2011
(490,912 real changes made)

. replace  electionperiod=2010 if year>2010 & year<2015
(520,716 real changes made)

. replace  electionperiod=2014 if year>2014 & year<2019
(0 real changes made)

. 
. *******************************************
. ** Join with precinct data. This is done **
. ** for the 2002, 2006 and 2010 precincts **
. *******************************************
. 
. 
. 
. foreach year in 2002 2006 2010 {
  2. preserve
  3. joinby xcoord ycoord using "$dat\xy_valdist_`year'.dta", unmatched(none)
  4. ren Valdist`year' Valdist
  5. gen llkk=substr(Valdist, 1, 4) 
  6. gen dist=substr(Valdist, 5, 4) 
  7. destring llkk dist, replace
  8. do "$do\mun code clean.do"
  9. sort electionperiod llkk dist temp
 10. collapse (mean) price_sqm* living_area*    (sum) sold_objects* ,  by(electionperiod llkk dist)
 11. 
. sort llkk dist election
 12. foreach var of varlist price_sqm-sold_objects_h {
 13. 
. gen `var'_lag = `var'[_n-1] if dist==dist[_n-1] & llkk==llkk[_n-1]  & election==(election[_n-1] +4)
 14. gen `var'_ch = `var'-`var'_lag 
 15. 
. gen `var'_lead = `var'[_n+1] if dist==dist[_n+1]  & llkk==llkk[_n-1] & election==(election[_n+1]-4)
 16. 
. }
 17. keep if election==`year' 
 18. gen year=election
 19. if `year'==2002 save "$dat\prices_precinct_ep.dta", replace
 20. else append using  "$dat\prices_precinct_ep.dta"
 21. save "$dat\prices_precinct_ep.dta", replace
 22. restore
 23. } 
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(1,133 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(15,730 missing values generated)
(16,250 missing values generated)
(14,744 missing values generated)
(5,760 missing values generated)
(5,762 missing values generated)
(5,994 missing values generated)
(10,263 missing values generated)
(10,441 missing values generated)
(9,978 missing values generated)
(6,881 missing values generated)
(6,988 missing values generated)
(6,923 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(5,707 missing values generated)
(5,707 missing values generated)
(5,992 missing values generated)
(11,280 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\prices_precinct_ep.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\prices_precinct_ep.dta saved
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(1,133 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(15,247 missing values generated)
(15,787 missing values generated)
(14,255 missing values generated)
(5,572 missing values generated)
(5,574 missing values generated)
(5,814 missing values generated)
(9,819 missing values generated)
(9,995 missing values generated)
(9,542 missing values generated)
(6,666 missing values generated)
(6,766 missing values generated)
(6,729 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(5,527 missing values generated)
(5,527 missing values generated)
(5,812 missing values generated)
(10,886 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\prices_precinct_ep.dta saved
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(14,797 missing values generated)
(15,358 missing values generated)
(13,788 missing values generated)
(5,405 missing values generated)
(5,407 missing values generated)
(5,658 missing values generated)
(9,300 missing values generated)
(9,478 missing values generated)
(9,015 missing values generated)
(6,516 missing values generated)
(6,604 missing values generated)
(6,593 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(5,371 missing values generated)
(5,371 missing values generated)
(5,657 missing values generated)
(10,597 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\prices_precinct_ep.dta saved

. 
. 
. 
. *************************
. *****    Home owners  ***
. *************************
. use "$dat\tenure500_midpoint.dta", clear

. 
. ren ostruta500  ycoord

. ren nordruta500 xcoord

. joinby xcoord ycoor  using "$dat\xy_valdist_2002.dta" , unmatched(master) 

. drop _merge

. joinby xcoord ycoor  using "$dat\xy_valdist_2006.dta" , unmatched(master) 

. drop _merge

. joinby xcoord ycoor  using "$dat\xy_valdist_2010.dta" , unmatched(master) 

. drop _merge

. gen  electionperiod=2002 if year==2002
(457,682 missing values generated)

. replace  electionperiod=2006 if year==2006 
(228,788 real changes made)

. replace  electionperiod=2010 if year ==2010
(228,894 real changes made)

. replace  electionperiod=2014 if year==2014
(0 real changes made)

. keep if electionperiod!=.
(0 observations deleted)

. 
. 
. foreach year in 2002 2006 2010{
  2. preserve 
  3. drop if mi(Valdist`year')
  4. ren Valdist`year' Valdist
  5. gen llkk=substr(Valdist, 1, 4) 
  6. gen dist=substr(Valdist, 5, 4) 
  7. destring llkk dist, replace
  8. do "$do\mun code clean.do" 
  9. drop if mi(dist)
 10. keep if electionperiod==`year'
 11. collapse (sum) pop owning_house- agriculture ,  by(electionperiod llkk dist)
 12. gen year=election
 13. if `year'==2002 save "$dat\tenure_precinct_ep.dta", replace
 14. else append using "$dat\tenure_precinct_ep.dta"
 15. save "$dat\tenure_precinct_ep.dta", replace
 16. restore
 17. } 
(440,535 observations deleted)
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(878 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(0 observations deleted)
(162,995 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\tenure_precinct_ep.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\tenure_precinct_ep.dta saved
(440,535 observations deleted)
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(878 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(0 observations deleted)
(162,355 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\tenure_precinct_ep.dta saved
(440,535 observations deleted)
llkk: all characters numeric; replaced as int
dist: all characters numeric; replaced as int

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(0 observations deleted)
(162,126 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\tenure_precinct_ep.dta saved

. 
. 
. ********************************
. *****  Building permits      ***
. ********************************
. 
. odbc load, exec("SELECT * FROM Bygglov") dsn("P0624") clear

. gen year=substr(ArManBygglovBeslut, 1, 4)

. gen month=substr(ArManBygglovBeslut, 5, 2)

. destring year month, replace
year: all characters numeric; replaced as int
month: all characters numeric; replaced as byte

. 
. gen YearMonth_sif=ym(year, month)

. format YearMonth %tm

. 
. g county=regexs(0) if regexm(Kommun, "^[0-9][0-9]")

. destring county, replace
county: all characters numeric; replaced as byte

. destring Kommun, replace
Kommun: all characters numeric; replaced as int

. 
. 
. *** Generating data sets with aggregated number of building perm ***
. * Use the years 2002--2014, drop some missing information on building type and valdistrikt and drop some variables
. 
. 
. * Aggregated over election period
. gen election_period=1994 if  ArManBygglovBeslut<"199810"
(241,686 missing values generated)

. replace election_period=1998 if ArManBygglovBeslut>"199810" & ArManBygglovBeslut<"200210"
(43,741 real changes made)

. 
.  replace election_period= 2002 if ArManBygglovBeslut>"200209" & ArManBygglovBeslut<"200610"
(54,123 real changes made)

. replace election_period=2006 if ArManBygglovBeslut>"200609" & ArManBygglovBeslut<"201010"
(54,833 real changes made)

.  replace election_period=2010 if ArManBygglovBeslut>"201009" & ArManBygglovBeslut<"201410"
(41,456 real changes made)

.  replace election_period=2014 if ArManBygglovBeslut>"201409" & ArManBygglovBeslut<"201810"
(46,618 real changes made)

. 
. 
. gen perm_tot=  BruttoAreaTot

. 
. ren AntLgh no_apt

. 
. 
. ** Number of perm, divided by type of permit
. foreach typ in 11 12 13 19 21  23 31 32 33 34 35 39 41 44 51 52  {
  2.  
. gen perm_`typ'=1 if  HuvudbyggnadsTyp==`typ'  
  3. 
. }
(126,260 missing values generated)
(265,800 missing values generated)
(260,471 missing values generated)
(224,797 missing values generated)
(257,693 missing values generated)
(266,451 missing values generated)
(263,004 missing values generated)
(262,924 missing values generated)
(264,745 missing values generated)
(262,841 missing values generated)
(263,996 missing values generated)
(266,186 missing values generated)
(243,508 missing values generated)
(251,065 missing values generated)
(265,444 missing values generated)
(266,512 missing values generated)

. ren perm_11 perm_onefam

. ren perm_12 perm_twofam

. ren perm_13 perm_chain

. ren perm_19 perm_vaca

. ren perm_21 perm_multi

. 
. 
. ***
. foreach typ in  onefam twofam chain multi  {
  2. gen area_`typ'= BruttoAreaTot  if perm_`typ'==1
  3. }
(126,260 missing values generated)
(265,800 missing values generated)
(260,471 missing values generated)
(257,693 missing values generated)

. 
. gen area_single = .
(266,926 missing values generated)

. gen no_single = .
(266,926 missing values generated)

. foreach typ in  onefam twofam chain   {
  2. replace area_single= BruttoAreaTot  if perm_`typ'==1
  3. replace no_single= no_apt  if perm_`typ'==1
  4. }
(140,666 real changes made)
(140,664 real changes made)
(1,126 real changes made)
(1,126 real changes made)
(6,455 real changes made)
(6,455 real changes made)

. 
. *** save statistics to use with appeals data in section A6 ****
. preserve

. keep if year==2017
(251,384 observations deleted)

. gen county_num=substr(Valdist2014, 1, 2) 
(300 missing values generated)

. destring county_num, replace
county_num: all characters numeric; replaced as byte
(300 missing values generated)

. bys county_num: egen multifam=sum(perm_multi)

. replace perm_onefam=perm_twofam if mi(perm_onefam)
(234 real changes made)

. replace perm_onefam=perm_chain if mi(perm_onefam)
(605 real changes made)

. bys county_num: egen onefam=sum(perm_onefam)

. keep county_num multifam onefam

. drop if mi(county_num)
(300 observations deleted)

. duplicates drop

Duplicates in terms of all variables

(15,221 observations deleted)

. save "$dat\permits_county_2017.dta", replace 
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits_county_2017.dta saved

. restore

. *********************
. 
. 
. foreach val in 2002 2006 2010 {
  2. preserve
  3. keep area_multi area_single election_period Valdist`val'
  4. ren Valdist`val' Valdist
  5. collapse (sum) area_multi area_single , by (election_period Valdist )
  6. fillin election Valdist
  7. sort Valdist election
  8. foreach var of varlist area_multi area_single {
  9. replace  `var'=0 if  `var'==.
 10. gen `var'_lag = `var'[_n-1] if Valdist==Valdist[_n-1]   & election==(election[_n-1] +4)
 11. replace  `var'_lag=0 if  `var'_lag==.
 12. gen `var'_lead = `var'[_n+1] if Valdist==Valdist[_n+1]  & election==(election[_n+1]-4)
 13. replace  `var'_lead=0 if  `var'_lead==.
 14. }
 15. gen llkk=substr(Valdist, 1, 4) 
 16. gen dist=substr(Valdist, 5, 4) 
 17. destring llkk dist, replace
 18. do "$do\mun code clean.do" // ok to do after collapse since no variation in municipality code within year
 19. keep if election==`val'
 20. gen year=election
 21. if `val'==2002 save "$dat\permits.dta", replace
 22. else append using  "$dat\permits.dta"
 23. save "$dat\permits.dta", replace
 24. restore
 25. } 
(12,241 real changes made)
(11,360 missing values generated)
(11,360 real changes made)
(11,360 missing values generated)
(11,360 real changes made)
(12,241 real changes made)
(11,360 missing values generated)
(11,360 real changes made)
(11,360 missing values generated)
(11,360 real changes made)
(7 missing values generated)
(7 missing values generated)
llkk: all characters numeric; replaced as int
(7 missing values generated)
dist: all characters numeric; replaced as int
(7 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(70 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(34,080 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits.dta saved
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits.dta saved
(11,783 real changes made)
(11,026 missing values generated)
(11,026 real changes made)
(11,026 missing values generated)
(11,026 real changes made)
(11,783 real changes made)
(11,026 missing values generated)
(11,026 real changes made)
(11,026 missing values generated)
(11,026 real changes made)
(7 missing values generated)
(7 missing values generated)
llkk: all characters numeric; replaced as int
(7 missing values generated)
dist: all characters numeric; replaced as int
(7 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(70 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(33,078 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits.dta saved
(11,549 real changes made)
(10,758 missing values generated)
(10,758 real changes made)
(10,758 missing values generated)
(10,758 real changes made)
(11,549 real changes made)
(10,758 missing values generated)
(10,758 real changes made)
(10,758 missing values generated)
(10,758 real changes made)
(7 missing values generated)
(7 missing values generated)
llkk: all characters numeric; replaced as int
(7 missing values generated)
dist: all characters numeric; replaced as int
(7 missing values generated)

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
(32,274 observations deleted)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits.dta saved

. 
. use  "$dat\permits.dta", clear

. 
. merge m:1 year llkk dist using "$dat\valdistrikt_alla.dta"

    Result                      Number of obs
    -----------------------------------------
    Not matched                         1,844
        from master                         7  (_merge==1)
        from using                      1,837  (_merge==2)

    Matched                            16,565  (_merge==3)
    -----------------------------------------

. 
. drop if dist==0
(209 observations deleted)

. drop if dist==9999
(580 observations deleted)

. foreach var of varlist  area_multi area_single   area_multi_lag- area_single_lead {
  2. replace `var'=0 if _merge==2
  3. }
(1,048 real changes made)
(1,048 real changes made)
(1,048 real changes made)
(1,048 real changes made)
(1,048 real changes made)
(1,048 real changes made)

. 
. replace election_period=year if _merge==2
(1,048 real changes made)

. drop _merge _fillin

. sum area_multi area_single // 17 630 obs

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
  area_multi |     17,620      1274.6    7065.714          0     247587
 area_single |     17,620    1343.776    3560.546          0     102723

. save "$dat\permits.dta", replace
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\permits.dta saved

.  
.  
. 
. 
. ***********************
. ****    Equipop    ****
. ***********************
. * Tar ut data för att skicka in i EquiPop
.  
.  foreach year in 2002 2006 2010 {
  2. * Geo:
. use "$dat\coordinates.dta", clear
  3. keep if year==`year'
  4. ren id p_id
  5. keep p_id sams xcoord ycoord llkk year
  6. do "$do\mun code clean.do"
  7. ren llkk kommunkod
  8. ren xcoord XKOORD_`year'
  9. ren ycoord YKOORD_`year'
 10. destring sams, gen(sams_`year') force 
 11. gen valar=`year'
 12. sum 
 13. 
. * Ålder och födelseregion
. joinby p_id year using "$dat\lisa_togeo.dta", unmatched(none) 
 14. keep if age>17
 15. 
. * Politik:
. joinby p_id valar using "$dat\mun politician data.dta", unmatched(master) 
 16. drop _merge
 17. 
. * Generate some variables
. gen politician_`year'=0
 18. replace politician_`year'=1 if  vald==1 
 19. drop if sams_`year'==.
 20. bysort sams_`year': egen sams_pop=count(p_id)
 21. sum sams_pop, det
 22. 
. gen highed=educ_year>13
 23. 
. gen ethnic_maj= 1-inv1g_eje
 24. 
. fasterxtile pct=inc, n(100)
 25. gen highq= pct>75 & pct!=.
 26. 
. save "$dat\MergedData\Merged_`year'.dta", replace
 27. }
(92,621,092 observations deleted)

. 
. replace llkk = 331 if llkk==1917
(10,413 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
sams: contains nonnumeric characters; sams_2002 generated as long
(161501 missing values generated)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        p_id |  9,077,702     7072037     4093339          1   1.42e+07
        year |  9,077,702        2002           0       2002       2002
   kommunkod |  7,043,169    1167.586    743.1881        114       2584
        sams |          0
   sams_2002 |  8,916,201    1.17e+07     7429048    1140001   2.58e+07
-------------+---------------------------------------------------------
 XKOORD_2002 |  8,934,422     6520939    389617.1          0    7644500
 YKOORD_2002 |  8,934,422     1474256    157103.5          0    1881000
       valar |  9,077,702        2002           0       2002       2002
(216,826 observations deleted)
(13,261 real changes made)
(17,089 observations deleted)

                          sams_pop
-------------------------------------------------------------
      Percentiles      Smallest
 1%          129              1
 5%          293              1
10%          425              1       Obs           6,981,805
25%          730              1       Sum of wgt.   6,981,805

50%         1216                      Mean           2005.325
                        Largest       Std. dev.      2491.209
75%         2055          16865
90%         4242          16865       Variance        6206124
95%         7147          16865       Skewness       3.143386
99%        12911          16865       Kurtosis       14.15006
(540 missing values generated)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\MergedData\Merged_2002.dta saved
(92,426,472 observations deleted)

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
sams: contains nonnumeric characters; sams_2006 generated as long
(190264 missing values generated)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        p_id |  9,272,322     7165666     4101159          1   1.42e+07
        year |  9,272,322        2006           0       2006       2006
   kommunkod |  7,220,287     1162.32    741.6894        114       2584
        sams |          0
   sams_2006 |  9,082,058    1.16e+07     7418480    1140001   2.58e+07
-------------+---------------------------------------------------------
 XKOORD_2006 |  9,102,920     6517186    402787.1          0    7644500
 YKOORD_2006 |  9,102,920     1473650    159128.7          0    1881000
       valar |  9,272,322        2006           0       2006       2006
(254,749 observations deleted)
(13,065 real changes made)
(19,570 observations deleted)

                          sams_pop
-------------------------------------------------------------
      Percentiles      Smallest
 1%          131              1
 5%          300              1
10%          434              1       Obs           7,157,824
25%          747              1       Sum of wgt.   7,157,824

50%         1252                      Mean           2039.922
                        Largest       Std. dev.      2498.063
75%         2096          16837
90%         4394          16837       Variance        6240317
95%         7278          16837       Skewness        3.09895
99%        12789          16837       Kurtosis        13.8995
(118 missing values generated)
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\MergedData\Merged_2006.dta saved
(92,109,433 observations deleted)

. 
. replace llkk = 331 if llkk==1917
(0 real changes made)

. replace llkk = 1438 if llkk==1504
(0 real changes made)

. replace llkk = 1439 if llkk== 1507
(0 real changes made)

. replace llkk = 1440 if llkk==1521
(0 real changes made)

. replace llkk = 1441 if llkk== 1524
(0 real changes made)

. replace llkk = 1442 if llkk== 1527
(0 real changes made)

. replace llkk = 1443 if llkk== 1535
(0 real changes made)

. replace llkk = 1444 if llkk== 1602
(0 real changes made)

. replace llkk = 1445 if llkk==1603
(0 real changes made)

. replace llkk = 1446 if llkk== 1637
(0 real changes made)

. replace llkk = 1447 if llkk== 1643
(0 real changes made)

. replace llkk = 1452 if llkk== 1552
(0 real changes made)

. replace llkk = 1460 if llkk== 1560
(0 real changes made)

. replace llkk = 1461 if llkk== 1561
(0 real changes made)

. replace llkk = 1462 if llkk== 1562
(0 real changes made)

. replace llkk = 1463 if llkk== 1563
(0 real changes made)

. replace llkk = 1465 if llkk== 1565
(0 real changes made)

. replace llkk = 1466 if llkk== 1566
(0 real changes made)

. replace llkk = 1470 if llkk==1660
(0 real changes made)

. replace llkk = 1471 if llkk==1661
(0 real changes made)

. replace llkk = 1472 if llkk== 1662
(0 real changes made)

. replace llkk = 1473 if llkk== 1663
(0 real changes made)

. replace llkk = 1487 if llkk== 1580
(0 real changes made)

. replace llkk = 1488 if llkk== 1581
(0 real changes made)

. replace llkk = 1489 if llkk== 1582
(0 real changes made)

. replace llkk = 1490 if llkk== 1583
(0 real changes made)

. replace llkk = 1491 if llkk== 1584
(0 real changes made)

. replace llkk = 1492 if llkk== 1585
(0 real changes made)

. replace llkk = 1493 if llkk== 1680
(0 real changes made)

. replace llkk = 1494 if llkk== 1681
(0 real changes made)

. replace llkk = 1495 if llkk==1682
(0 real changes made)

. replace llkk = 1496 if llkk== 1683
(0 real changes made)

. replace llkk = 1497 if llkk== 1684
(0 real changes made)

. replace llkk = 1498 if llkk== 1685
(0 real changes made)

. replace llkk = 1499 if llkk== 1686
(0 real changes made)

. 
. replace llkk =642  if llkk== 1622 
(0 real changes made)

. replace llkk = 643 if llkk==1623 
(0 real changes made)

. 
. replace llkk =1256      if llkk==       1121
(0 real changes made)

. replace llkk =1257      if llkk==       1137
(0 real changes made)

. replace llkk =1270 if llkk==    1160    
(0 real changes made)

. replace llkk =1272      if llkk==       1162
(0 real changes made)

. replace llkk =1273      if llkk==       1163
(0 real changes made)

. replace llkk =1275 if llkk==    1165    
(0 real changes made)

. replace llkk =1276      if llkk==       1166
(0 real changes made)

. replace llkk =1277 if llkk==    1167    
(0 real changes made)

. replace llkk =1278 if llkk==    1168    
(0 real changes made)

. replace llkk =1290 if llkk==    1180    
(0 real changes made)

. replace llkk =1291      if llkk==       1181
(0 real changes made)

. replace llkk =1292      if llkk==       1182
(0 real changes made)

. replace llkk =1293      if llkk==       1183
(0 real changes made)

. 
end of do-file
sams: contains nonnumeric characters; sams_2010 generated as long
(200928 missing values generated)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        p_id |  9,589,361     7262055     4102910          1   1.42e+07
        year |  9,589,361        2010           0       2010       2010
   kommunkod |  7,513,556     1151.23     740.898        114       2584
        sams |          0
   sams_2010 |  9,388,433    1.14e+07     7413497    1140001   2.58e+07
-------------+---------------------------------------------------------
 XKOORD_2010 |  9,401,851     6520173    352264.3          0    7644500
 YKOORD_2010 |  9,401,851     1475317    153310.3          0    1881000
       valar |  9,589,361        2010           0       2010       2010
(352,798 observations deleted)
(12,961 real changes made)
(12,150 observations deleted)

                          sams_pop
-------------------------------------------------------------
      Percentiles      Smallest
 1%          135              1
 5%          311              1
10%          449              1       Obs           7,482,465
25%          773              1       Sum of wgt.   7,482,465

50%         1305                      Mean           2171.851
                        Largest       Std. dev.      2674.039
75%         2221          17366
90%         4692          17366       Variance        7150487
95%         8146          17366       Skewness       3.017008
99%        13078          17366       Kurtosis       13.23655
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\MergedData\Merged_2010.dta saved

. 
. 
. 
. * High-educated for EquiPop
. foreach year in 2002 2006 2010 {
  2. use "$dat\MergedData\Merged_`year'.dta", clear
  3. sort XKOORD_`year' YKOORD_`year'
  4. by XKOORD_`year' YKOORD_`year': egen pop=count(p_id)
  5. replace pop=0 if pop==.
  6. by XKOORD_`year' YKOORD_`year': egen pop_highed=count(p_id) if highed==1
  7. replace pop_highed=0 if pop_highed==.
  8.  
. collapse (max) p_id pop pop_highed, by(XKOORD_`year' YKOORD_`year')
  9. sum
 10. export delimit "$dat\To_EquiPop\highed_`year'.dat", delimit(tab) replace
 11. }
(0 real changes made)
(5,014,850 missing values generated)
(5,014,850 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2002 |    234,070     6574208    293549.1    6137000    7644500
 YKOORD_2002 |    234,070     1465881    133755.7    1223000    1881000
        p_id |    234,070    1.06e+07     3481752        674   1.42e+07
         pop |    234,070    29.82785    140.3067          1       6878
  pop_highed |    234,070    8.403277    55.56933          0       4106
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highed_2002.dat saved
(0 real changes made)
(4,953,769 missing values generated)
(4,953,769 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2006 |    232,150     6571896    291834.7    6136500    7644500
 YKOORD_2006 |    232,150     1465950    133547.2    1223000    1881000
        p_id |    232,150    1.07e+07     3418786        674   1.42e+07
         pop |    232,150    30.83275    143.6719          1       6874
  pop_highed |    232,150    9.494099    61.20589          0       4375
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highed_2006.dat saved
(0 real changes made)
(4,987,905 missing values generated)
(4,987,905 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2010 |    230,859     6569360    289952.9    6136500    7644500
 YKOORD_2010 |    230,859     1465548    133318.7    1223000    1881000
        p_id |    230,859    1.09e+07     3354294        384   1.42e+07
         pop |    230,859    32.41141    151.4331          1       7015
  pop_highed |    230,859    10.80556    68.96142          0       4590
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highed_2010.dat saved

. 
. 
. 
. * High-earners (upper quartile) for EquiPop
. foreach year in 2002 2006 2010 {
  2. use "$dat\MergedData\Merged_`year'.dta", clear
  3. sort XKOORD_`year' YKOORD_`year'
  4. by XKOORD_`year' YKOORD_`year': egen pop=count(p_id)
  5. replace pop=0 if pop==.
  6. by XKOORD_`year' YKOORD_`year': egen pop_highq=count(p_id) if highq==1
  7. replace pop_highq=0 if pop_highq==.
  8.  
. collapse (max) p_id pop pop_highq, by(XKOORD_`year' YKOORD_`year')
  9. sum
 10. export delimit "$dat\To_EquiPop\highq_`year'.dat", delimit(tab) replace
 11. }
(0 real changes made)
(5,236,973 missing values generated)
(5,236,973 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2002 |    234,070     6574208    293549.1    6137000    7644500
 YKOORD_2002 |    234,070     1465881    133755.7    1223000    1881000
        p_id |    234,070    1.06e+07     3481752        674   1.42e+07
         pop |    234,070    29.82785    140.3067          1       6878
   pop_highq |    234,070    7.454317    41.14295          0       3425
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highq_2002.dat saved
(0 real changes made)
(5,370,236 missing values generated)
(5,370,236 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2006 |    232,150     6571896    291834.7    6136500    7644500
 YKOORD_2006 |    232,150     1465950    133547.2    1223000    1881000
        p_id |    232,150    1.07e+07     3418786        674   1.42e+07
         pop |    232,150    30.83275    143.6719          1       6874
   pop_highq |    232,150    7.700142    40.98525          0       3379
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highq_2006.dat saved
(0 real changes made)
(5,613,225 missing values generated)
(5,613,225 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2010 |    230,859     6569360    289952.9    6136500    7644500
 YKOORD_2010 |    230,859     1465548    133318.7    1223000    1881000
        p_id |    230,859    1.09e+07     3354294        384   1.42e+07
         pop |    230,859    32.41141    151.4331          1       7015
   pop_highq |    230,859     8.09689     44.2481          0       3644
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\highq_2010.dat saved

. 
. 
. * Ethnic majority for EquiPop
. foreach year in 2002 2006 2010 {
  2. use "$dat\MergedData\Merged_`year'.dta", clear
  3. sort XKOORD_`year' YKOORD_`year'
  4. by XKOORD_`year' YKOORD_`year': egen pop=count(p_id)
  5. replace pop=0 if pop==.
  6. by XKOORD_`year' YKOORD_`year': egen pop_ethnic_maj=count(p_id) if ethnic_maj==1
  7. replace pop_ethnic_maj=0 if pop_ethnic_maj==.
  8.  
. collapse (max) p_id pop pop_ethnic_maj, by(XKOORD_`year' YKOORD_`year')
  9. sum
 10. export delimit "$dat\To_EquiPop\ethnic_maj_`year'.dat", delimit(tab) replace
 11. }
(0 real changes made)
(463,460 missing values generated)
(463,460 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2002 |    234,070     6574208    293549.1    6137000    7644500
 YKOORD_2002 |    234,070     1465881    133755.7    1223000    1881000
        p_id |    234,070    1.06e+07     3481752        674   1.42e+07
         pop |    234,070    29.82785    140.3067          1       6878
pop_ethnic~j |    234,070    27.84784    125.8097          0       6597
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\ethnic_maj_2002.dat saved
(0 real changes made)
(569,059 missing values generated)
(569,059 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2006 |    232,150     6571896    291834.7    6136500    7644500
 YKOORD_2006 |    232,150     1465950    133547.2    1223000    1881000
        p_id |    232,150    1.07e+07     3418786        674   1.42e+07
         pop |    232,150    30.83275    143.6719          1       6874
pop_ethnic~j |    232,150     28.3815    126.4918          0       6546
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\ethnic_maj_2006.dat saved
(0 real changes made)
(723,267 missing values generated)
(723,267 real changes made)

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
 XKOORD_2010 |    230,859     6569360    289952.9    6136500    7644500
 YKOORD_2010 |    230,859     1465548    133318.7    1223000    1881000
        p_id |    230,859    1.09e+07     3354294        384   1.42e+07
         pop |    230,859    32.41141    151.4331          1       7015
pop_ethnic~j |    230,859    29.27847    129.9513          0       6626
file \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Data\To_EquiPop\ethnic_maj_2010.dat saved

. 
. log close
      name:  <unnamed>
       log:  \\micro.intra\Projekt\P0624$\P0624_Gem\Politisk Geografi\Results\log\setup.log
  log type:  text
 closed on:   2 Oct 2023, 16:28:18
-------------------------------------------------------------------------------------------------------------------------------------
